<?php

/**
 * 一些常用的类
 * 
 * @author ShuangYa
 * @package Blog
 * @category Library
 * @link http://www.sylingd.com/
 * @copyright Copyright (c) 2015 ShuangYa
 * @license http://lab.sylingd.com/go.php?name=blog&type=license
 */

namespace blog\libs;
use \Sy;
use \sy\lib\YMysql;
use \sy\base\SYException;
use \blog\libs\BHtml;


//列表操作类
class ListSub_Action {
	protected $sub;
	public function __construct($sub) {
		$this->sub = $sub;
	}
	public function __call($name, $args) {
		if (isset($this->sub[$name])) {
			if (is_array($args) && count($args) > 0) {
				echo $this->sub[$name];
			} else {
				echo BHtml::encode($this->sub[$name]);
			}
		} else {
			throw new SYException('Method ' . $name . ' not exists', '20000');
		}
	}
	public function __get($name) {
		if (isset($this->sub[$name])) {
			return $this->sub[$name];
		} else {
			return NULL;
		}
	}
	public function __set($k, $v) {
		if (isset($this->sub[$k])) {
			$this->sub[$k] = $v;
		} elseif ($k !== 'sub') {
			$this->$k = $v;
		} else {
			throw new SYException('Sub is readonly', '20001');
		}
	}
}
class List_Action {
	public $list;
	/**
	 * 构造函数
	 * @access public
	 * @param array $list
	 */
	public function __construct($list) {
		$this->list = $list;
		reset($this->list);
	}
	/**
	 * 移到下一个
	 * @access public
	 * @return array
	 */
	public function next() {
		$r = each($this->list);
		if ($r === FALSE) {
			return FALSE;
		} else {
			return new ListSub_Action($r['value']);
		}
	}
	/**
	 * 重新开始
	 * @access public
	 */
	public function reset() {
		reset($this->list);
	}
	/**
	 * 获取全部
	 * @access public
	 * @return array
	 */
	public function getAll() {
		return $this->list;
	}
}
